package com.yuqiao.read.design.observer2java;

import java.util.Observable;
import java.util.Observer;

public class ForecastDisplay implements Observer,DisplayElement {
    private float tempTure,huimiDity,pressure;
    private Observable observable;
    public void display() {
        System.out.println("天氣預報"+tempTure+"shidu"+huimiDity+"qiya"+pressure);
    }

    public ForecastDisplay(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData){
            WeatherData weatherData = (WeatherData) o;
            this.huimiDity = weatherData.getHumidity();
            this.tempTure = weatherData.getTemp();
            this.pressure = weatherData.getPressure();
            display();
        }
    }
}
